<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

include_spip('functions/pdk_common');

function formulaires_alohacart_extension_traiter_dist($id_extension){
	$result = array();
     
    //$shipping = pdk_load_class('AlohacartShippingFlat','classes/shipping');
    $extension_mdl = pdk_load_class('AlohacartExtensionModel','classes/');
    $extension = $extension_mdl->select_by_id($id_extension);
    $extension_handler = $extension_mdl->GetExtensionClassByID($id_extension);
    try {
        $data = $extension_mdl->form_data_from_array($_REQUEST);
        
        if (!$extension_mdl->update_by_id($id_extension, $data, true))
            throw new Exception("Extension save fail!");
            
        $data = array();
        foreach ($extension_handler->fields as $field) {                
           $data[$field] = _request('extension_'.$field);  
        }
        $data['free_from'] = _request('extension_free_from'); 
        if (!$extension_handler->SaveMetaData($data))
            throw new Exception("Extension meta data save fail!");
        
        $result['message_ok'] = _T('alohacart:form_saved');
    } catch(Exception $e) {
        $result['message_erreur'] = _T('alohacart:form_error');
    }
     
	return $result;
}